package com.ydy.service.impl;

import com.ydy.enums.YesOrNo;
import com.ydy.mapper.CarouselMapper;
import com.ydy.pojo.Carousel;
import com.ydy.resource.ServerUri;
import com.ydy.service.CarouselService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**轮播图**/
@Service
public class CarouselServiceImpl implements CarouselService {

    public static final Logger log =
            LoggerFactory.getLogger(CarouselServiceImpl.class);

    @Autowired
    private CarouselMapper carouselMapper;

    @Autowired
    private ServerUri serverUri;

    /**
     * 查询首页轮播图
     * @Title: queryAll
     * @author: dy.yin 2022/1/14 8:59
     * @return: {@link List< Carousel> }
     */
    @Override
    public List<Carousel> queryAll() {
        Example example = new Example(Carousel.class);
        //按排序字段排序
        example.orderBy("sort").desc();
        Example.Criteria criteria = example.createCriteria();
        //是否展示  是
        criteria.andEqualTo("isShow", YesOrNo.YES.type);
        log.info("查询首页轮播图");
        List<Carousel> list = carouselMapper.selectByExample(example);
        list.forEach(v ->{
            v.setImageUrl(serverUri.appendImagUrl(v.getImageUrl()));
        });
        return list;
    }
}
